<template>
  <view>
    <view class="input-search">
    	<uni-easyinput prefixIcon="search"  trim="all" v-model="keyword" :styles="styles" :placeholderStyle="placeholderStyle"></uni-easyinput>
		<button @click="search">搜索</button>
    </view>
    
    <!-- stripe type="selection" 开启多选 -->
    <uni-table ref="table" type="selection" :loading="loading" emptyText="暂无更多数据" filter-type="search"  @selection-change="selectionChange">
	  <uni-tr>
		<uni-th>
			<view class="close_btn" v-show="head.FSynStatus==1?false:true" @click="toDelete">删除</view>
		</uni-th>
	</uni-tr>
        <uni-tr v-for="(item, index) in card_arr" :key="index" >
			<uni-td width="100%" align="left" class="td-class" >
				<div @click="selectes(item)">
					<!-- <view>
						<text>单号：{{ item.FBillNo }}</text>
					</view> -->
					<view>
						<text>名称：{{ item.FName }}</text>
					</view>
					<view>
						<text>编码：{{ item.FNumber }}</text>
						<text>规格{{ item.FModel }}</text>
					</view>
					<view>
						<text>批号：{{ item.pihao }}</text>
						<text>箱头：{{ item.boxhead }}</text>
					</view>
					<view>
						<text>单位：{{ item.FUnit_Name }}</text>
					</view>
					<view>
						<text>出库数量：{{ item.FQty }}</text>
					</view>
				</div>
			</uni-td>
        </uni-tr>
    </uni-table>
	
    <view class="uni-pagination-box">
		<uni-pagination show-icon :page-size="pageSize" :current="currentPage"
        :total="total" @change="change" />
	</view>
  </view>
</template>

<script>
// 引入uni-ui组件
import {
  uniPagination,
  uniIcons,
  uniCard,
  uniTable,
  uniTr,
  uniTh,
  uniTd,
  uniEasyinput,
  //uniDataSelect
} from "@dcloudio/uni-ui"

export default {
	components: {
	  uniPagination,
	  uniTable,
	  uniTr,
	  uniTh,
	  uniTd,
	  uniEasyinput,
	},
  data() {
    return {
      card_arr: [],//当前页码的表格数据
      pageSize: 15,// 每页数据量
      currentPage: 1,// 当前页
      total: 0,// 数据总量
      loading: false,
	  placeholderStyle:'font-size:16px;',
	  styles:{
	  	borderColor: '#999'
	  },
	  keyword:'',
	  where:'',
	  selectedIndexs:[],//选中
      head:[]
    }
  },
  methods: {
    // 多选
	selectionChange(e) {
		this.selectedIndexs = e.detail.index
	},
    toDelete() {
		let _this = this;
		let delFlag = true;
      uni.showModal({
          title: '确定要删除记录？',
          success: function (res) {
              if (res.confirm) {
				  if(_this.selectedIndexs.length>0){
					 _this.selectedIndexs.forEach(key=>{
						 if(_this.head.FSynStatus==1){
							 _this.$Api.msg("已同步，无法删除");
							 _this.$refs.table.clearSelection()
							 delFlag = false;
						 }
					 })
					 
					 if(delFlag){
						//删除本地记录
						uni.showLoading({});
						_this.selectedIndexs.forEach(key=>{
								_this.$Db.deleteTableData('stockbillentry','FBillNo',_this.head.FBillNo,'FEntryID',key+1)
								_this.$Api.msg('删除成功','success')
								_this.$refs.table.clearSelection()
						})
						uni.hideLoading()
						_this.search()
					 }
				  }
              } else if (res.cancel) {
                  return false;
              }
          }
      });
    },
    selectes(item) {
      
    },
	// 搜索
	search() {
		this.currentPage = 1;
		this.getlist();
	},
    //获取列表
    async getlist() {
		if(this.head.length==0)
		return 
		uni.showLoading();
		let _this = this
		this.where = " FBillNo = '"+this.head.FBillNo+"' "
		if(this.keyword!=''){
			this.where += " and (FName like '%"+this.keyword+"%' or FNumber like '%"+this.keyword+"%' or pihao like '%"+this.keyword+"%' or boxhead like '%"+this.keyword+"%') "
		}
		await this.$Db.queryCount('stockbillentry_view',this.where).then(res => {
			this.total = res[0].num;//获得总页数
		})
		await this.$Db.queryDataList('stockbillentry_view',this.currentPage,this.pageSize,this.where).then(res => {
			this.card_arr = res
		})
		uni.hideLoading();
    },
    change(e) {
      this.currentPage = e.current
      this.getlist()
    }
  },
  mounted(e) {
    this.getlist()
  },
  onLoad(e) {
	let _this = this
	uni.$off("getOtherOutItem")
	uni.$on("getOtherOutItem",(item) => {
		_this.head = item
		_this.getlist()
	})
  }
}
</script>